package org.cloud.controller;

import cn.hutool.core.date.DateUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.cloud.apis.PaymentFeignService;
import org.cloud.model.dto.PayDto;
import org.cloud.response.ResultData;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * ClassName: PayController
 * Package: org.cloud.controller
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2024/4/10 - 21:30
 * @Version: v1.0
 */
@Slf4j
@RestController
@RequestMapping("/feign")
@RequiredArgsConstructor
public class PaymentFeignController {

    private final PaymentFeignService paymentFeignService;

    /**
     * 一般情况下，通过浏览器的地址栏输入url，发送的只能是get请求
     * 我们底层调用的是post方法，模拟消费者发送get请求，客户端消费者
     * 参数可以不添加@RequestBody
     * @param payDTO
     * @return
     */
    @GetMapping("/pay/add")
    public ResultData addOrder(PayDto payDTO){
        paymentFeignService.addOrder(payDTO);
        return ResultData.success();
    }

    /**
     * @param orderNo
     * @return
     */
    @GetMapping("/pay/query/{orderNo}")
    public ResultData queryOrder(@PathVariable("orderNo") String orderNo){
        ResultData resultData = null;
        try
        {
            System.out.println("调用开始-----:"+DateUtil.now());
            resultData = paymentFeignService.queryOrder(orderNo);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("调用结束-----:"+ DateUtil.now());
            ResultData.fail();
        }
        return resultData;
    }
}
